package com.jt.demo22.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

@Component
@Aspect
@Order(value = 2)
public class TestAspect {
        @Pointcut("bean(userServiceImpl)")
        public void pointCut(){
        }
        @Before(value = "pointCut()")
        public void before(){
            System.out.println("前置通知 贝仁杰2货");

        }

        @AfterReturning(value = "pointCut()",returning = "result")
        public void afterReturning(Object result){
                System.out.println("后置通知");
                System.out.println("方法的返回值"+result);
        }

        @AfterThrowing(value = "pointCut()",throwing = "exception")
        public void afterThrowing(Exception exception){
                //打印错误信息
                System.out.println("出错！："+exception.getLocalizedMessage());
        }

        @After(value = "pointCut()")
        public void after(){
                System.out.println("最终通知");
        }

        @Around(value = "pointCut()")
        public void around(ProceedingJoinPoint point) throws Throwable {
                System.out.println("环绕1");
                Object proceed = point.proceed();
                System.out.println("环绕1");
                System.out.println("环绕返回："+proceed);

        }


}
